package Limit.Game.MarkSix;

/**
 *  
 * @author Lihuan 2012.4.8 edit
 */
public class MarkSixCheck {

	private String resultNum[] = new String[6];//公布的幸运号码
	private String ticketNum[] = new String[6];//玩家下注的号码
	private int numType;//票種
	private int wager;//賭注
	public int bonus;//獎金
	//賠率設置 　　　　　　　　　　　[大小單雙,特碼,二星,三星,四星,六中三,六中三半,六中四,六中四半,六中五,六中五半,六中六]
	private int[] odds = new int[] {18,40,57,570,6700,4,32,64,960,9000,18000,27000};
	
	public MarkSixCheck(String[] resultNum,String[] ticketNum,int numType,int wager){
		this.resultNum = resultNum;
		this.ticketNum = ticketNum;
		this.numType = numType;
		this.wager = wager;
	}
	
	//檢測是否中獎
	public boolean CheckNum(){
	
		int tempN = 0;

		//檢測台灣特碼
		if (numType == 1 && ticketNum[0].equals(resultNum[6])){
			bonus = wager * odds[1];
			return true;
		}		
		//小
		else if (numType == 7){ 
			int i =  Integer.valueOf(resultNum[6]).intValue();
			if (i < 25)
			{
				bonus = wager * odds[0] / 10;
				return true;
			}
		}		
		//大
		else if (numType == 8){
			int i =  Integer.valueOf(resultNum[6]).intValue();
			if (i > 24)
			{
				bonus = wager * odds[0] / 10;
				return true;
			}
		}		
		//單
		else if (numType == 9){
			int i =  Integer.valueOf(resultNum[6]).intValue();
			if (i % 2 != 0)
			{
				bonus = wager * odds[0] / 10;
				return true;
			}
		}		
		//雙
		else if (numType == 10){
			int i =  Integer.valueOf(resultNum[6]).intValue();
			if (i % 2 == 0)
			{
				bonus = wager * odds[0] / 10;
				return true;
			}
		}
		
		if (numType > 6)
			return false;
		
		//檢測其他類型
		for (int i = 0; i < numType; i++){
			for (int j=0; j < resultNum.length; j++){
				if (ticketNum[i].equals(resultNum[j])){
					tempN++;
				}
				if (ticketNum[i].equals(resultNum[6])) {
					tempN += 100;
				}
				
			}
		}

		if (numType < 5 && numType == tempN){
			//檢測台灣二星、三星、四星
			switch (tempN){
			case 2:
				bonus = wager * odds[2];
				return true;
			case 3:
				bonus = wager * odds[3];
				return true;
			case 4:
				bonus = wager * odds[4];
				return true;		
			}
		}
		else if (numType == 6 && tempN > 2){//核對香港六合彩
			//未中特碼
			switch (tempN){
			case 3:
				bonus = wager * odds[5];
				return true;
			case 4:
				bonus = wager * odds[7];
				return true;
			case 5:
				bonus = wager * odds[9];
				return true;
			case 6:
				bonus = wager * odds[11];
				return true;			
			}
			//中特碼
			switch (tempN){
			case 103:
				bonus = wager * odds[6];
				return true;
			case 104:
				bonus = wager * odds[8];
				return true;
			case 105:
				bonus = wager * odds[10];
				return true;		
			}
			
		}
		return false;		
	}
}
